﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Bootstrap5.Design;


internal class FlexDecoratorProvider : BreakPointClassDecoratorProvider<string,BreakingPointModel,IFlexDecorator>, IFlexDecorator
{

    public IFlexDecorator Fill => GetKey("flex-{breakpoint}fill");

    public IFlexDecorator JustifyContentStart => GetKey("justify-content-{breakpoint}start");

    public IFlexDecorator JustifyContentEnd => GetKey("justify-content-{breakpoint}end");

    public IFlexDecorator JustifyContentCenter => GetKey("justify-content-{breakpoint}center");

    public IFlexDecorator JustifyContentBetween => GetKey("justify-content-{breakpoint}between");

    public IFlexDecorator JustifyContentAround => GetKey("justify-content-{breakpoint}around");

    public IFlexDecorator JustifyContentEvenly => GetKey("justify-content-{breakpoint}evenly");

    public IFlexDecorator AlignItemsStart => GetKey("align-items-{breakpoint}start");

    public IFlexDecorator AlignItemsEnd => GetKey("align-items-{breakpoint}end");

    public IFlexDecorator AlignItemsCenter => GetKey("align-items-{breakpoint}center");

    public IFlexDecorator AlignItemsBaseline => GetKey("align-items-{breakpoint}baseline");

    public IFlexDecorator AlignItemsStretch => GetKey("align-items-{breakpoint}stretch");

    public IFlexDecorator AlignSelfStart => GetKey("align-self-{breakpoint}start");

    public IFlexDecorator AlignSelfEnd => GetKey("align-self-{breakpoint}end");

    public IFlexDecorator AlignSelfCenter => GetKey("align-self-{breakpoint}center");

    public IFlexDecorator AlignSelfBaseline => GetKey("align-self-{breakpoint}baseline");

    public IFlexDecorator AlignSelfStretch => GetKey("align-self-{breakpoint}stretch");

    public IFlexDecorator AlignContentStart => GetKey("align-content-{breakpoint}start");

    public IFlexDecorator AlignContentEnd => GetKey("align-content-{breakpoint}end");

    public IFlexDecorator AlignContentCenter => GetKey("align-content-{breakpoint}center");

    public IFlexDecorator AlignContentAround => GetKey("align-content-{breakpoint}around");

    public IFlexDecorator AlignContentStretch => GetKey("align-content-{breakpoint}stretch");

    public IFlexDecorator Row => GetKey("flex-{breakpoint}row");

    public IFlexDecorator RowReserve => GetKey("flex-{breakpoint}row-reserve");

    public IFlexDecorator Column => GetKey("flex-{breakpoint}column");

    public IFlexDecorator ColumnReserve => GetKey("flex-{breakpoint}column-reserve");

    public IFlexDecorator Shrink => GetKey("flex-{breakpoint}shrink-1");

    public IFlexDecorator NoShrink => GetKey("flex-{breakpoint}shrink-0");

    public IFlexDecorator Grow => GetKey("flex-{breakpoint}grow-1");

    public IFlexDecorator NoGrow => GetKey("flex-{breakpoint}grow-0");

    public IFlexDecorator OrderFirst => GetKey("order-{breakpoint}first");

    public IFlexDecorator OrderLast => GetKey("order-{breakpoint}last");

    public IFlexDecorator Order0 => GetKey("order-{breakpoint}0");

    public IFlexDecorator Order1 => GetKey("order-{breakpoint}1");

    public IFlexDecorator Order2 => GetKey("order-{breakpoint}2");

    public IFlexDecorator Order3 => GetKey("order-{breakpoint}3");

    public IFlexDecorator Order4 => GetKey("order-{breakpoint}4");

    public IFlexDecorator Order5 => GetKey("order-{breakpoint}5");

    public IFlexDecorator Wrap => GetKey("flex-{breakpoint}wrap");

    public IFlexDecorator WrapReserve => GetKey("flex-{breakpoint}wrap-reserve");

    public IFlexDecorator NoWrap => GetKey("flex-{breakpoint}nowrap");

    public IFlexDecorator NoWrapReserve => GetKey("flex-{breakpoint}nowrap-reserve");

    protected override IFlexDecorator GetBreakPoint(BreakPoint breakPoint)
    {
        SetBreakPoint(breakPoint);
        return this;
    }

    protected override IFlexDecorator GetKey(string key)
    {
        SetKey(key);
        return this;
    }
    protected override void BuildClass()
    {
        Rules.AddRange(RuleDic.Select(m => GetCssClass(m.Key, m.Value)));
    }

    string GetCssClass(string key, IEnumerable<BreakingPointModel> values)
    {
        return string.Join(" ", values.Select(m => GetCssClass(key, m.BreakPoint)));
    }

    string GetCssClass(string key, BreakPoint? breakingPoint)
    {
        return key.Replace("{breakpoint}", GetBreakPointString(breakingPoint));
    }
}
